package com.hschinese.pronunciation.utils;

import android.content.Context;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;

import com.hschinese.pronunciation.activity.MyApplication;
import com.tencent.android.tpush.XGIOperateCallback;
import com.tencent.android.tpush.XGPushManager;

import okhttp3.Call;

public class HttpUtils {
	
	public static <T> T getResult(Class<T> clazz, Call call){
		T t = null;
		if(null != call){

		}
		return t;
	}
	
	/**
	 * 检测网络是否可用
	 * 
	 * @param _context  上下文
	 * @return
	 */
	public static boolean isNetworkValid(Context _context) {
		ConnectivityManager connectivity = (ConnectivityManager) _context
				.getSystemService(Context.CONNECTIVITY_SERVICE);
		if (connectivity != null) {
			NetworkInfo[] info = connectivity.getAllNetworkInfo();
			if (info != null)
				for (int i = 0; i < info.length; i++)
					if (info[i].getState() == NetworkInfo.State.CONNECTED) {
						return true;
					}
		}
		return false;
	}

	public static void registerPush(String email){
		XGPushManager.registerPush(MyApplication.getInstance(), email, new XGIOperateCallback() {
			@Override
			public void onSuccess(Object arg0, int arg1) {
				setLabel(arg0.toString());
			}

			@Override
			public void onFail(Object arg0, int arg1, String arg2) {
			}
		});
	}

	private static void setLabel(final String token){
		ThreadPoolUtil.getInstance().execute(new Runnable() {
			@Override
			public void run() {
//				NetWorkService mService = new NetWorkService();
//				Call call = mService.getSetLabelCall(MyApplication.getInstance().getLanguage(), Utils.getUniqueCode(MyApplication.getInstance()),
//						Utils.getDeviceName(), token, UserInfoUtil.getInstance(MyApplication.getInstance()).getEmail(),
//						UserInfoUtil.getInstance(MyApplication.getInstance()).getUid(), Constant.PRODUCT_ID, "2100094764");
//				HttpUtils.getResult(BaseBean.class, call);
			}
		});
	}

}
